package com.luming.controller;

import com.luming.entity.FinancialData;
import com.luming.service.FinancialDataService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/financial")
@RequiredArgsConstructor
public class TestController {
    
    private final FinancialDataService financialDataService;
    
    @PostMapping("/save")
    public String saveData(@RequestBody FinancialData data) {
        financialDataService.saveData(data);
        return "Data saved successfully";
    }
    
    @GetMapping("/year/{year}")
    public List<FinancialData> getByYear(@PathVariable Integer year) {
        return financialDataService.getByFiscalYear(year);
    }
    
    @GetMapping("/name/{name}")
    public List<FinancialData> getByName(@PathVariable String name) {
        return financialDataService.getByDataName(name);
    }
    
    @PostMapping("/test/batch")
    public String testBatchInsert() {
        financialDataService.testBatchInsert();
        return "Batch insert test completed";
    }
    
    @PostMapping("/test/transaction")
    public String testTransaction() {
        try {
            financialDataService.testCrossYearTransaction();
            return "Transaction test completed successfully";
        } catch (Exception e) {
            return "Transaction test failed with error: " + e.getMessage();
        }
    }
}